package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.SysPtQuestionVo;
import com.ruoyi.system.bo.SysPtQuestionQueryBo;
import com.ruoyi.system.bo.SysPtQuestionAddBo;
import com.ruoyi.system.bo.SysPtQuestionEditBo;
import com.ruoyi.system.service.ISysPtQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 实验题目Controller
 *
 * @author ruoyi
 * @date 2021-11-28
 */
@Api(value = "实验题目控制器", tags = {"实验题目管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/SysQuestion")
public class SysPtQuestionController extends BaseController {

    private final ISysPtQuestionService iSysPtQuestionService;

    /**
     * 查询实验题目列表
     */
    @ApiOperation("查询实验题目列表")
    @PreAuthorize("@ss.hasPermi('system:SysQuestion:list')")
    @GetMapping("/list")
    public TableDataInfo<SysPtQuestionVo> list(@Validated SysPtQuestionQueryBo bo) {
        return iSysPtQuestionService.queryPageList(bo);
    }

    /**
     * 导出实验题目列表
     */
    @ApiOperation("导出实验题目列表")
    @PreAuthorize("@ss.hasPermi('system:SysQuestion:export')")
    @Log(title = "实验题目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysPtQuestionVo> export(@Validated SysPtQuestionQueryBo bo) {
        List<SysPtQuestionVo> list = iSysPtQuestionService.queryList(bo);
        ExcelUtil<SysPtQuestionVo> util = new ExcelUtil<SysPtQuestionVo>(SysPtQuestionVo.class);
        return util.exportExcel(list, "实验题目");
    }

    /**
     * 获取实验题目详细信息
     */
    @ApiOperation("获取实验题目详细信息")
    @PreAuthorize("@ss.hasPermi('system:SysQuestion:query')")
    @GetMapping("/{questionId}")
    public AjaxResult<SysPtQuestionVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("questionId") Long questionId) {
        return AjaxResult.success(iSysPtQuestionService.queryById(questionId));
    }

    /**
     * 新增实验题目
     */
    @ApiOperation("新增实验题目")
    @PreAuthorize("@ss.hasPermi('system:SysQuestion:add')")
    @Log(title = "实验题目", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysPtQuestionAddBo bo) {
        return toAjax(iSysPtQuestionService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改实验题目
     */
    @ApiOperation("修改实验题目")
    @PreAuthorize("@ss.hasPermi('system:SysQuestion:edit')")
    @Log(title = "实验题目", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysPtQuestionEditBo bo) {
        return toAjax(iSysPtQuestionService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除实验题目
     */
    @ApiOperation("删除实验题目")
    @PreAuthorize("@ss.hasPermi('system:SysQuestion:remove')")
    @Log(title = "实验题目" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{questionIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] questionIds) {
        return toAjax(iSysPtQuestionService.deleteWithValidByIds(Arrays.asList(questionIds), true) ? 1 : 0);
    }
}
